package com.gitee.wsl.mathematics.algebraic.op

import com.gitee.wsl.mathematics.algebraic.Algebra


/**
 * A context extension to include power operations based on exponentiation.
 *
 * @param T the type of this structure element
 */
 interface PowerOperations<T>: Algebra<T> {

    /**
     * Raises [arg] to a power if possible (negative number could not be raised to a fractional power).
     * Throws [IllegalArgumentException] if not possible.
     */
     fun power(arg: T, pow: Number): T

    /**
     * Computes the square root of the value [arg].
     */
     fun sqrt(arg: T): T = power(arg, 0.5)

    /**
     * Raises this value to the power [pow].
     */
     infix fun T.pow(pow: Number): T = power(this, pow)

     companion object {
        /**
         * The identifier of exponentiation.
         */
         const val POW_OPERATION: String = "pow"

        /**
         * The identifier of square root.
         */
         const val SQRT_OPERATION: String = "sqrt"
    }
}